package com.xbai.creation.abstractfactory;

import com.xbai.creation.abstractfactory.factory.GUIFactory;
import com.xbai.creation.abstractfactory.factory.MacOSFactory;
import com.xbai.creation.abstractfactory.factory.WindowsFactory;

public class Demo {

    /**
     * 应用程序选择工厂类型并在运行时（通常在初始化阶段）创建它，具体取决于配置或环境变量
     */
    private static Application configureApplication() {
        Application app;
        GUIFactory factory;
        String osName = System.getProperty("os.name").toLowerCase();
        if (osName.contains("mac")) {
            factory = new MacOSFactory();
            app = new Application(factory);
        } else {
            factory = new WindowsFactory();
            app = new Application(factory);
        }
        return app;
    }

    public static void main(String[] args) {
        Application app = configureApplication();
        app.paint();
    }
}